package impl

import (
	"SkyPath/internal/domain/user/entry"
	gw "SkyPath/internal/domain/user/gateway"
	svc "SkyPath/internal/domain/user/service"
	"log"
)

// 确保 UserDomainServiceImpl 实现了 svc.UserDomianService 接口
var _ svc.UserDomianService = (*UserDomainServiceImpl)(nil)

// UserDomainServiceImpl 是 UserDomianService 接口的实现
type UserDomainServiceImpl struct {
	userGateway gw.UserDomainGateway // 通过依赖注入传入 Gateway
}

// NewUserDomainServiceImpl 创建一个新的服务实例
func NewUserDomainServiceImpl(gateway gw.UserDomainGateway) *UserDomainServiceImpl {
	return &UserDomainServiceImpl{
		userGateway: gateway,
	}
}

// GetUserById 根据用户 ID 获取用户信息
func (u *UserDomainServiceImpl) GetUserById(id int) (*entry.User, error) {
	log.Printf("domain user service GetUserById: id = %d", id)

	user, err := u.userGateway.GetUserById(id)
	if err != nil {
		return nil, err
	}

	return user, nil
}

// GetUserByAccount 根据账号获取用户信息
func (u *UserDomainServiceImpl) GetUserByAccount(account string) (*entry.User, error) {
	log.Printf("domain user service GetUserByAccount: account = %s", account)

	user, err := u.userGateway.GetUserByAccount(account)
	if err != nil {
		return nil, err
	}

	return user, nil
}

// GetUserByEmail 根据邮箱获取用户信息
func (u *UserDomainServiceImpl) GetUserByEmail(email string) (*entry.User, error) {
	log.Printf("domain user service GetUserByEmail: email = %s", email)

	user, err := u.userGateway.GetUserByEmail(email)
	if err != nil {
		return nil, err
	}

	return user, nil
}

// GetUserByPhone 根据手机号获取用户信息
func (u *UserDomainServiceImpl) GetUserByPhone(phone string) (*entry.User, error) {
	log.Printf("domain user service GetUserByPhone: phone = %s", phone)

	user, err := u.userGateway.GetUserByPhone(phone)
	if err != nil {
		return nil, err
	}

	return user, nil
}

// GetUserByName 根据用户名获取用户信息
func (u *UserDomainServiceImpl) GetUserByName(name string) (*entry.User, error) {
	log.Printf("domain user service GetUserByName: name = %s", name)

	user, err := u.userGateway.GetUserByName(name)
	if err != nil {
		return nil, err
	}

	return user, nil
}
